package unq.uis.robots.ui;

import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.bindings.Transformer;
import org.uqbar.arena.layout.HorizontalLayout;
import org.uqbar.arena.layout.VerticalLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.windows.SimpleWindow;
import org.uqbar.arena.windows.WindowOwner;

import unq.uis.robots.applicationsModels.PelearApplicationModel;


public class ResultadoPeleaWindow extends SimpleWindow<PelearApplicationModel>{

	public ResultadoPeleaWindow(WindowOwner parent, PelearApplicationModel model) {
		super(parent, model);
	}

	private static final long serialVersionUID = 1L;

	@Override
	protected void addActions(Panel actionsPanel) {
		new Button(actionsPanel)
		.setCaption("Cerrar")
		.onClick(new MessageSend(this, "close"))
		.setAsDefault()
		.disableOnError();
	}

	@Override
	protected void createFormPanel(Panel mainPanel) {
		this.crearDatosResultadosPelea(mainPanel);
		
	}

	public void crearDatosResultadosPelea(Panel mainPanel){
		Panel panel = new Panel(mainPanel);
		panel.setLayout(new VerticalLayout());

		Panel resultadoPanel = new Panel(panel);
		resultadoPanel.setLayout(new HorizontalLayout());
		
		Label elGanador = new Label(resultadoPanel);
		elGanador.setFontSize(12);
		elGanador.setText("Usted: ");
		
		Label gano = new Label(resultadoPanel);
		gano.setFontSize(12);
		gano.bindValueToProperty("pelea.resultado")
			.setTransformer(new Transformer<Boolean, String>(){

				@Override
				public Boolean viewToModel(String valueFromView) {
					return valueFromView == "Gano";
				}

				@Override
				public String modelToView(Boolean valueFromModel) {
					return valueFromModel ? "Gano" : "Perdio";
				}
				

				@Override
				public Class<Boolean> getModelType() {
					return Boolean.class;
				}

				@Override
				public Class<String> getViewType() {
					return String.class;
				}
			
				
			});
		

		Panel gananciaPanel = new Panel(panel);
		gananciaPanel.setLayout(new HorizontalLayout());
		
		Label laGanancia = new Label(gananciaPanel);
		laGanancia.setFontSize(12);
		laGanancia.setText("Su ganancia es de: $");
		
		Label ganancia = new Label(gananciaPanel);
		ganancia.setFontSize(12);
		ganancia.bindValueToProperty("pelea.ganancia");

		
		Panel desgastePanel = new Panel(panel);
		desgastePanel.setLayout(new HorizontalLayout());
		
		Label elDesgaste = new Label(desgastePanel);
		elDesgaste.setFontSize(12);
		elDesgaste.setText("El Desgaste de su Robot es: %");
		
		Label porcentajeDanio = new Label(desgastePanel);
		porcentajeDanio.setFontSize(12);
		porcentajeDanio.bindValueToProperty("pelea.porcentajeDesgaste");
	}
}
